<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>幻灯片配置</title>
<link rel="shortcut icon" href="favicon.ico">
<link href="${pageContext.request.contextPath}/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
<link href="${pageContext.request.contextPath}/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<link href="${pageContext.request.contextPath}/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/css/animate.min.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/css/style.min.css?v=4.1.0" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>幻灯片配置</h5>
        </div>
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <div class="example-wrap">
                        <!-- start toolbar -->
                        <div class="col-sm-12">
                            <form class="form-horizontal" role="form" id="slideShowForm">
                                <div class="row">
                                    <div class="col-sm-3">
                                    	<button type="button" class="btn btn-primary" id="uploadBtn">
                                            <span class="glyphicon glyphicon-cloud-upload" aria-hidden="true"></span> 上传图片
                                        </button>
                                    	<button type="button" class="btn btn-primary" id="addBtn">
                                            <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> 新增
                                        </button>
                                        <button type="button" class="btn btn-info" id="" onclick="location.reload();">
                                            <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> 刷新
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <!-- end toolbar -->
                        <div class="example">
                            <table id="slideShowTab" class="table" data-click-to-select="true" data-mobile-responsive="true">
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/js/jquery.min.js?v=2.1.4"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${pageContext.request.contextPath}/js/content.min.js?v=1.0.0"></script>
<script src="${pageContext.request.contextPath}/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="${pageContext.request.contextPath}/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="${pageContext.request.contextPath}/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="${pageContext.request.contextPath}/js/plugins/layer/layer.min.js"></script>
<script src="${pageContext.request.contextPath}/js/public/ttbj-core.js"></script>
<script type="text/javascript">
var $table = $("#slideShowTab");
$(function () {
    initTable();
  	//增加按钮
    $("#addBtn").click(function () {
    	initSlideShowEdit(null);
    });
  	//上传图片
    $("#uploadBtn").click(function () {
    	uploadSlideShowImg();
    });
});

function initTable() {
    $table.bootstrapTable({
    	dataType: "json",
        showColumns: true,
        singleSelect : true,
        pagination: true, //分页
        striped: true,
        cache: false,	//是否使用缓存，默认是true
        pageSize: 10,
        pageNumber: 1,
        queryParamsType: 'limit',
        smartDisplay: true,
        sidePagination: "server",
        queryParams: queryParams,
        method: "post",	//使用post提交
        url: '../slideshow/getSlideShowMag.htm',
        contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
        columns: [
            {
                title: "图片",
                field: "slideImgName",
                align: 'center',
                valign: 'middle',
                formatter: function(value, row, index){
                	if(row.slideImgName != null){
	                	var e = '<a class="view" href="javascript:void(0)"><img class="carousel-inner img-responsive center-block" style="width:50px;height:50px" src="${pageContext.request.contextPath}/img/slideshow/' + row.slideImgName + '"/></a>';
    	            	return e;
                	}
                },
                events: 'operateEvents'	//定义点击之后放大图片的事件
            },
            {
            	title: "图片排序",
                field: "slideOrder",
                align: 'center',
                valign: 'middle'
            },
            {
            	title: "添加时间",
                field: "slideInsTime",
                align: 'center',
                valign: 'middle'
            },
            {
            	title: "更新时间",
                field: "slideUpdateTime",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "操作",
                align: 'center',
                formatter: function (value, row, index) {
                    var e = '<button class="btn btn-xs btn-info" type="button" onclick="initSlideShowEdit(\'' + row.slideId + '\')"><i class="fa fa-edit"></i> 编辑</button> ';
                    var d = '<button class="btn btn-xs btn-danger" type="button" onclick="deleteSlideShow(\'' + row.slideId + '\',\'' + row.slideImgName + '\')"><i class="fa fa-trash-o"></i> 删除 </button> ';
                    return e + d;
                }
            }
        ],
        onClickRow: function(row, $element, field){	//当点击某一行时，该行背景颜色改变
        	var trObj = $($element[0]);
        	var dataIndex = trObj.attr('data-index');
        	$("tr[data-index != '" + dataIndex + "']").removeAttr('style');
        	trObj.attr('style', 'background: #B4EEB4');
        }
	});
}

//分页参数，条件查询时的参数
function queryParams(queryParamsType){
	var temp = {
		limit: queryParamsType.limit,   //页面大小
		offset: queryParamsType.offset  //页码
	};
	return temp;
}
    
//新增和编辑幻灯片
function initSlideShowEdit(id){
    var title;
    if(id){
        title = '编辑幻灯片';
    }else{
        title = '新增幻灯片';
    }
    var index = layer.open({
        type: 2,
        title: title,
        maxmin: true,
        shadeClose: false, //点击遮罩关闭层
        area : ['500px' , '750px'],
        content: '../slideshow/edit_show_slide.htm?slideId='+id,
        success: function(layero, index){
        }
    });
}

//上传图片
function uploadSlideShowImg(){
    var index = layer.open({
        type: 2,
        title: '上传图片',
        maxmin: true,
        shadeClose: false, //点击遮罩关闭层
        area : ['90%' , '90%'],
        content: '../slideshow/slide_show_upload.htm',
        success: function(layero, index){
        }
    });
}

//删除幻灯片
function deleteSlideShow(slideId, slideName) {
    layer.confirm('你确定要删除【' + slideName + '】此配置吗？', {
        btn: ['删除', '取消'] //按钮
    }, function () {
        $.ajax({
            url: "../slideshow/delSlideShowInfo.htm",
            cache: false,
            type: "post",
            dataType: "json",
            data: {'slideId': slideId},
            success: function (result) {
                if (result.status == 0) {
                    layer.msg(result.message, {icon: 1});
                    $table.bootstrapTable('refresh', {url: '../slideshow/getSlideShowMag.htm'});
                    return;
                }
                layer.msg(result.message, {icon: 2});
            }
        });
    }, function () {
    });
}

//点击之后放到图片
window.operateEvents = {'click .view': function(e, value, row, index) {
		var url = '${pageContext.request.contextPath}/img/slideshow/' + row.slideImgName;
		var index = layer.open({
			type: 1,
		    title: row.slideImgName,
		    closeBtn: 0,
		    area: ['50%', '70%'],
			closeBtn:1, 
		    shadeClose: true,
		    content: '<img class="carousel-inner img-responsive center-block" style="width:100%;height:100%" src="' + url + '"/>'
		});
	}
};
</script>
</body>
</html>